﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Customer_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    //触发验证
    protected void Login_member_Authenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        Authenticated = SiteLevelCustomAuthenticationMethod(Login_member.UserName, Login_member.Password);
        e.Authenticated = Authenticated;
        if (Authenticated == true)
        {
            FormsAuthentication.SetAuthCookie(Login_member.UserName, false);
            //Response.Redirect("~/Default.aspx");
        }
    }
    //遍历数据库进行用户验证
    private bool SiteLevelCustomAuthenticationMethod(string userName, string password)
    {
        bool boolReturnValue = false;
        Members members = new Members();
        foreach (var mem in members.GetAllMembers())
        {
            if (userName == mem.userName && password == mem.passWord)
            {
                boolReturnValue = true;
            }
        }
        Admins admins = new Admins();
        foreach (var ad in admins.GetAllAdmins())
        {
            if (userName == ad.managerName&& password == ad.pwd)
            {
                boolReturnValue = true;
            }
        }

        return boolReturnValue;
    }
}
